package com.yuexun.dhdoctor.module.departmentDocumentNew.adapter;

import android.view.View;
import android.widget.AbsListView;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.departmentDocumentNew.bean.MemberListBean;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.Collection;

/**
 * Created by wangt on 2017/7/20.
 */

public class AlreadyShareObjListAdapter extends KJAdapter<MemberListBean> {

    boolean isDo;

    public void setDo(boolean aDo) {
        isDo = aDo;
        notifyDataSetChanged();
    }

    public AlreadyShareObjListAdapter(AbsListView view, Collection<MemberListBean> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder helper, final MemberListBean item, boolean isScrolling) {
        RelativeLayout rl = helper.getView(R.id.rl_doc_department_select);
        TextView title = helper.getView(R.id.tv_doc_department_select_title);
        CheckBox selectView = helper.getView(R.id.checkbox_doc_department_select);
        ImageView icArrow = helper.getView(R.id.img_doc_department_arrow);
        title.setText(item.getMemeberName());
        icArrow.setVisibility(View.GONE);

        if (isDo) {
            selectView.setVisibility(View.VISIBLE);
            rl.setClickable(true);
            rl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (item.isSelect()){
                        item.setSelect(false);
                    }else{
                        item.setSelect(true);
                    }
                    notifyDataSetChanged();
                }
            });
        } else {
            selectView.setVisibility(View.GONE);
            rl.setClickable(false);
        }

        selectView.setChecked(item.isSelect());
    }

}
